package com.qianfeng.missfood.ui;

import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qianfeng.missfood.R;

public class Category_Details_Search_Activity extends AppCompatActivity implements View.OnClickListener{
    @ViewInject(R.id.meishisichu_click)
    View meishisichu_click;
    @ViewInject(R.id.meishisichu)
    TextView meishisichu_text;
    private PopupWindow popupWindow;
    private boolean popFlag=true;
    private View meishiclick;
    private View sichuclick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category__details__search_);
        ViewUtils.inject(this);
        initView();
    }

    private void initView() {
        View popView=getLayoutInflater().inflate(R.layout.category_detail_search_popupwindow_layout,null);
        //得到两个可点击的view
        meishiclick = popView.findViewById(R.id.meishi_click);
        sichuclick = popView.findViewById(R.id.sichu_click);
        popupWindow = new PopupWindow(popView);//把视图放入popupWindow中
        popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        meishisichu_click.setOnClickListener(this);
        meishiclick.setOnClickListener(this);
        sichuclick.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        //这个v是点击的那个v,也就是说点击谁就把要显示的内容显示在点击的那个东西下边
        switch (v.getId()){
            case R.id.meishisichu_click:
                //显示popupWindow
                if(popFlag){
                    popupWindow.showAsDropDown(v,0,25);
                    popFlag=false;
                }else if(!popFlag){
                    popupWindow.dismiss();
                    popFlag=true;
                }
                break;
            case R.id.meishi_click:
                meishisichu_text.setText("美食");
                popupWindow.dismiss();
                popFlag=true;
                break;
            case R.id.sichu_click:
                meishisichu_text.setText("私厨");
                popupWindow.dismiss();
                popFlag=true;
                break;

        }



    }
}
